home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / interp18.lha / interp-1.8 / util.cc < prev   
C/C++ Source or Header  |  1990-01-20  |  2KB  |  102 lines

  1. // util.cc -- utility routines for the parser.
  2. // Copyright (C) 1989 Carey Richard Murphey.
  3. // (rich@rice.edu) 5310 Rutherglenn, Houston, TX 77096
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 1, or (at your option)
  8. // any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stream.h>
  20. #include <math.h>
  21. #include <ctype.h>
  22. #include "parser.h"
  23.  
  24. Double_Pointer d (0.);
  25. StringSymbolpAVLMap global_table (& d); // global symbol table
  26.  
  27. Context context (&global_table); // the set of symbol tables
  28.  
  29. int
  30. yyerror (const char *const s)
  31. {
  32.   cerr << "// " << s << '\n';
  33.   return 0;
  34. }
  35.  
  36. t_func* print_table;
  37.  
  38. double
  39. print_table (double x)
  40. {
  41.   cerr << "\t\t\t// the contents of the symbol table:\n";
  42.   for (Pix ind = global_table.first(); ind; global_table.next(ind))
  43.     {
  44.       cerr << "\t// " << global_table.key(ind) << " = ";
  45.       global_table.contents(ind)->echo(cerr);
  46.       cerr << "\n";
  47.     }
  48.   cerr << "\t\t\t// end of symbol table.\n";
  49.   return 0.;
  50. }
  51.  
  52. t_func* print_value;
  53.  
  54. double
  55. print_value (double x)
  56. {
  57.   cerr << "\t// " << x << "\n";
  58.   return x;
  59. }
  60.  
  61. struct init
  62. {
  63.   char *fname;
  64.   t_func* fnct;
  65. };
  66.  
  67. struct init builtin[] =
  68. {
  69.   "acos",    acos,
  70.   "asin",    asin,
  71.   "atan",    atan,
  72.   "ceil",    ceil,
  73.   "cos",    cos,
  74.   "cosh",    cosh,
  75.   "exp",    exp,
  76.   "fabs",    fabs,
  77.   "floor",    floor,
  78.   "gamma",    gamma,
  79.   "j0",        j0,
  80.   "j1",        j1,
  81.   "ln",        log,
  82.   "log",    log,
  83.   "log10",    log10,
  84.   "sin",    sin,
  85.   "sinh",    sinh,
  86.   "sqrt",    sqrt,
  87.   "tan",    tan,
  88.   "tanh",    tanh,
  89.   "y0",        y0,
  90.   "y1",        y1,
  91.   "print_table", print_table,
  92.   "print_value", print_value,
  93.   0, 0
  94.   };
  95.  
  96. void
  97. init_parser ()
  98. {
  99.   for (int i = 0; builtin[i].fname; i++)
  100.     global_table[builtin[i].fname] = new Function (builtin[i].fnct);
  101. }
  102.